package com.kiragame.xchat.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class User {
	private Integer userID;
	private String name;
	private UserInfo userInfo;

	public Integer getUserID() {
		return userID;
	}

	public void setUserID(Integer userID) {
		this.userID = userID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static User fromJsonToUser(String json) {
		return new JSONDeserializer<User>().use(null, User.class).deserialize(
				json);
	}

	public static String toJsonArray(Collection<User> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<User> fromJsonArrayToUsers(String json) {
		return new JSONDeserializer<List<User>>().use(null, ArrayList.class)
				.use("values", User.class).deserialize(json);
	}
}
